<template>
    <div>
        <div>
            <el-form :inline="true" :model="formInline" size="mini" class="demo-form-inline">
                <el-form-item label="图号">
                    <el-input v-model="formInline.itemCode" placeholder="图号"></el-input>
                </el-form-item>
                <el-form-item label="质量编号">
                    <el-input v-model="formInline.qualityCode" placeholder="质量编号"></el-input>
                </el-form-item>
                <el-form-item label="缓存箱编号">
                    <el-input v-model="formInline.workbinCode" placeholder="缓存箱编号"></el-input>
                </el-form-item>
                <el-form-item label="台账ID">
                    <el-input v-model="formInline.wmsItemInventoryId" placeholder="台账ID"></el-input>
                </el-form-item>
                <el-form-item label="交接单ID">
                    <el-input v-model="formInline.wmsDeliveryPlanId" placeholder="交接单ID"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="doQuery">查询</el-button>
                    <el-button type="primary" @click="doReset">重置</el-button>
                    <el-button type="primary" @click="updateWorkbin">修改箱子</el-button>
                    <el-button size="mini" type="primary" @click="SetEmptyBoxes">设置空箱</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <el-table  :data="tableData" style="width: 100%" height="500" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column prop="itemCode" label="图号" width="180"></el-table-column>
                <el-table-column prop="qualityCode" label="质量编号" width="120"> </el-table-column>
                <el-table-column prop="itemQty" label="数量" width="120"> </el-table-column>
                <el-table-column prop="workbinCode" label="箱子号" width="140"> </el-table-column>
                <el-table-column prop="mesCheckQualiticationId" label="合格证号" > </el-table-column>
                <el-table-column prop="msWorkbinMaterialId" label="箱子表主键" > </el-table-column>
                <el-table-column prop="wmsDeliveryPlanId" label="交接单表主键" > </el-table-column>
                <el-table-column prop="wmsItemInventoryId" label="台账表主键" > </el-table-column>
            </el-table>
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.currentPage"
                :page-sizes="[20, 50, 100, 400]" :page-size="page.pageSize" layout="total, sizes, prev, pager, next" :total="page.total">
            </el-pagination>
        </div>
        <div>
            <el-dialog title="箱子" :visible.sync="dialog.dialogFormVisible" label-width="100">
                <el-form :model="form" :inline="true" size="mini">
                    <el-form-item label="图号">
                        <el-input v-model="form.itemCode" autocomplete="off" ></el-input>
                    </el-form-item>
                    <el-form-item label="质量编号">
                        <el-input v-model="form.qualityCode" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="数量">
                        <el-input v-model="form.itemQty" autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="箱子号">
                        <el-input v-model="form.workbinCode" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size="mini" @click="dialog.dialogFormVisible = false">取 消</el-button>
                    <el-button size="mini" type="primary" @click="saveData">确 定</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>

<script>
import request from "@/utils/request.js";
export default{
    name:"workbinMaterialQuery",
    data(){
        return {
            formInline:{itemCode:"",qualityCode:"",workbinCode:"",wmsItemInventoryId:"",wmsDeliveryPlanId:""},
            tableData:[],
            page:{currentPage:1,total:0,pageSize:20},
            selectData:[],
            form:{},
            dialog:{
                dialogFormVisible:false
            }
        }
    },
    methods:{
        SetEmptyBoxes(){
            // if(this.selectData.length==0){
            //     this.$Alert({title:"失败",type:"error",message:"请至少选择一条数据"})
            //     return ;
            // }
            var message = "";
            var A = Math.ceil(Math.random()*100);
            var B = Math.ceil(Math.random()*10);
            var C = Math.ceil(Math.random()*100);
            var D = Math.ceil(Math.random()*100);
            message = "请将 "+A+"/"+B+"+"+C+"%"+D+" 计算的结果输入到输入框中!";
            console.log(Math.floor(A/B)+"============"+C%D);
            var result = Math.floor(A/B)+C%D;
            this.$prompt(message,"提示",{ 
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'}
            ).then(({value})=>{
                console.log("value",value);
                console.log("result",result);
                if(result != value){
                    this.$Alert({type:"error",title:"成功",message:"计算的结果不对"});
                    return;
                }
                request.post("/msworkbin/SetEmptyBoxes").then((res)=>{
                console.log("res",res);
                if(res.data.retCode=="200"){
                    this.$Alert({type:"success",title:"成功",message:res.data.message});
                }else{
                    this.$Alert({type:"error",title:"失败",message:res.data.message});
                }
            })
            });
            
        },
        doQuery(){
            request.post("/msworkbin/queryWorkbinMaterial",{queryParam:this.formInline,page:this.page}).then((res)=>{
                console.log("res",res);
                this.tableData = res.data.list;
                this.page.total = res.data.total;
            });
        },
        doReset(){
            Object.assign(this.formInline,this.$options.data().formInline);
        },
        handleCurrentChange(val){
            this.page.currentPage = val;
            this.doQuery();
        },
        handleSizeChange(val){
            this.page.pageSize = val;
            this.doQuery();
        },
        handleSelectionChange(val){
            this.selectData = val;
        },
        updateWorkbin(){
            if(this.selectData.length!=1){
                this.$Alert({title: "错误", message: '请选择一条数据',type: "error"});
                return;
            }
            this.form = this.selectData[0];
            this.dialog.dialogFormVisible = true;
        },
        saveData(){
            var message = "";
            var A = Math.ceil(Math.random()*100);
            var B = Math.ceil(Math.random()*10);
            var C = Math.ceil(Math.random()*100);
            var D = Math.ceil(Math.random()*100);
            message = "请将 "+A+"/"+B+"+"+C+"%"+D+" 计算的结果输入到输入框中!";
            console.log(Math.floor(A/B)+"============"+C%D);
            var result = Math.floor(A/B)+C%D;
            this.$prompt(message,"提示",{ 
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'}
            ).then(({value})=>{
                console.log("value",value);
                console.log("result",result);
                if(result != value){
                    this.$Alert({type:"error",title:"成功",message:"计算的结果不对"});
                    return;
                }
                request.post("/msworkbin/updateWorkbinMaterial",this.form).then((res)=>{
                    if(res.data.retCode=="200"){
                        this.$Alert({title: "成功", message: '操作成功',type: "success"});
                    }else{
                        this.$Alert({title: "错误", message: '操作失败',type: "error"});
                    }
                    this.dialog.dialogFormVisible = false;
                    this.$options.methods.doQuery.bind(this)();
                })
            })
        }
    }
}
</script>